package com.cms.util;

import javax.servlet.ServletContext;

import org.apache.struts2.views.freemarker.FreemarkerManager;


import freemarker.template.Configuration;
import freemarker.template.TemplateException;

public class MyFreemarkerManager extends FreemarkerManager{
	public synchronized Configuration getConfiguration(ServletContext servletcontext)
	{
		Configuration configuration = (Configuration)servletcontext.getAttribute("freemarker.Configuration");
		if (configuration == null){
			try {
				configuration = createConfiguration(servletcontext);
			} catch (TemplateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	/**	
		SubstringMethod substringMethod = (SubstringMethod)SpringUtil.getBean("substringMethod");
		CheckboxDirective checkboxDirective = (CheckboxDirective)SpringUtil.getBean("checkboxDirective");
		PaginationDirective paginationDirective = (PaginationDirective)SpringUtil.getBean("paginationDirective");
		CommentListDirective commentListDirective = (CommentListDirective)SpringUtil.getBean("commentListDirective");
		NavigationListDirective navigationListDirective = (NavigationListDirective)SpringUtil.getBean("navigationListDirective");
		FriendLinkListDirective friendLinkListDirective = (FriendLinkListDirective)SpringUtil.getBean("friendLinkListDirective");
		InstantMessagingListDirective instantMessagingListDirective = (InstantMessagingListDirective)SpringUtil.getBean("instantMessagingListDirective");
		ArticleCategoryListDirective articleCategoryListDirective = (ArticleCategoryListDirective)SpringUtil.getBean("articleCategoryListDirective");
		ArticleCategoryTreeDirective articleCategoryTreeDirective = (ArticleCategoryTreeDirective)SpringUtil.getBean("articleCategoryTreeDirective");
		ArticleListDirective articleListDirective = (ArticleListDirective)SpringUtil.getBean("articleListDirective");	
		configuration.setSharedVariable("substring", substringMethod);
		configuration.setSharedVariable("checkbox", checkboxDirective);
		configuration.setSharedVariable("pagination", paginationDirective);
		configuration.setSharedVariable("comment_list", commentListDirective);
		configuration.setSharedVariable("navigation_list", navigationListDirective);
		configuration.setSharedVariable("friend_link_list", friendLinkListDirective);
		configuration.setSharedVariable("instant_messaging_list", instantMessagingListDirective);
		configuration.setSharedVariable("article_category_list", articleCategoryListDirective);
		configuration.setSharedVariable("article_category_tree", articleCategoryTreeDirective);
		configuration.setSharedVariable("article_list", articleListDirective);
			**/
		servletcontext.setAttribute("freemarker.Configuration", configuration);
		}
		configuration.setWhitespaceStripping(true);
		return configuration;
	}
}
